#!/bin/bash

source ../scripts/common.sh

MYSQL_DEFAULT_PASSWORD=zwh.fly

APT_CONFIG_VERSION=0.8.20-1
APT_CONFIG_MD5SUM=4126e44e0867531a4724ab0c21d1d645

# 
apt -y install gnupg
download "http://repo.mysql.com/mysql-apt-config_${APT_CONFIG_VERSION}_all.deb" "mysql-apt-config_${APT_CONFIG_VERSION}_all.deb" $APT_CONFIG_MD5SUM
dpkg -i mysql-apt-config_${APT_CONFIG_VERSION}_all.deb
apt update && apt -y install mysql-server

#1. 开启远程访问和计划任务
sed -i "s#bind-address\s*=\s*127.0.0.1#bind-address= 0.0.0.0\nsql_mode = \nevent_scheduler = 1\n#" /etc/mysql/mysql.conf.d/mysqld.cnf
 
 
mysql --user=root --password=${MYSQL_DEFAULT_PASSWORD} mysql -e \
"grant all privileges on *.* to 'root'@'%' identified by '${MYSQL_DEFAULT_PASSWORD}' with grant option; flush privileges;"

systemctl restart mysql.service


#apt -y install mariadb-server
#sed -i "s#bind-address\s*=\s*127.0.0.1#bind-address= 0.0.0.0\nsql_mode = \nevent_scheduler = 1\n#" /etc/mysql/mariadb.conf.d/50-server.cnf
#sed -i "s#datadir\s*= /var/lib/mysql#datadir = /data/mysql#" /etc/mysql/mariadb.conf.d/50-server.cnf
#mysql --user=root --password=${MYSQL_DEFAULT_PASSWORD} mysql -e "grant all privileges on *.* to 'root'@'%' identified by '${MYSQL_DEFAULT_PASSWORD}' with grant option; flush privileges;"
 
